(function(){"use strict";BX.namespace("BX.Grid");BX.Grid.InlineEditor=function(t,e){this.parent=null;this.types=null;this.init(t,e)};BX.Grid.InlineEditor.prototype={init:function(parent,types){this.parent=parent;try{this.types=eval(types)}catch(t){this.types=null}},createContainer:function(){return BX.create("div",{props:{className:this.parent.settings.get("classEditorContainer")}})},createTextarea:function(t,e){var n=BX.create("textarea",{props:{className:[this.parent.settings.get("classEditor"),this.parent.settings.get("classEditorTextarea")].join(" ")},attrs:{name:t.NAME,style:"height:"+e+"px"},html:t.VALUE});return n},createInput:function(t){var e=this.parent.settings.get("classEditorText");var n={value:t.VALUE!==undefined&&t.VALUE!==null?BX.util.htmlspecialcharsback(t.VALUE):"",name:t.NAME!==undefined&&t.NAME!==null?t.NAME:""};if(t.TYPE===this.types.CHECKBOX){e=this.parent.settings.get("classEditorCheckbox");n.type="checkbox";n.checked=n.value=="Y"}if(t.TYPE===this.types.DATE){e=[e,this.parent.settings.get("classEditorDate")].join(" ")}if(t.TYPE===this.types.NUMBER){e=[e,this.parent.settings.get("classEditorNumber")].join(" ");n.type="number"}if(t.TYPE===this.types.RANGE){e=[e,this.parent.settings.get("classEditorRange")].join(" ");n.type="range";if(BX.type.isPlainObject(t.DATA)){n.min=t.DATA.MIN||"0";n.max=t.DATA.MAX||99999;n.step=t.DATA.STEP||""}}e=[this.parent.settings.get("classEditor"),e].join(" ");return BX.create("input",{props:{className:e,id:t.NAME+"_control"},attrs:n})},createCustom:function(t){var e=this.parent.settings.get("classEditorCustom");e=[this.parent.settings.get("classEditor"),e].join(" ");return BX.create("div",{props:{className:e},attrs:{"data-name":t.NAME},html:t.VALUE||""})},createOutput:function(t){return BX.create("output",{props:{className:this.parent.settings.get("classEditorOutput")||""},attrs:{for:t.NAME+"_control"},text:t.VALUE||""})},getDropdownValueItemByValue:function(t,e){var n=t.filter(function(t){return t.VALUE===e});return n.length>0?n[0]:t[0]},createDropdown:function(t){var e=this.getDropdownValueItemByValue(t.DATA.ITEMS,t.VALUE);return BX.create("div",{props:{className:[this.parent.settings.get("classEditor"),"main-dropdown main-grid-editor-dropdown"].join(" "),id:t.NAME+"_control"},attrs:{name:t.NAME,"data-items":JSON.stringify(t.DATA.ITEMS),"data-value":e.VALUE},children:[BX.create("span",{props:{className:"main-dropdown-inner"},html:e.NAME})]})},validateEditObject:function(t){return BX.type.isPlainObject(t)&&"TYPE"in t&&"NAME"in t&&"VALUE"in t&&(!("items"in t)||BX.type.isArray(t.items)&&t.items.length)},initCalendar:function(t){BX.calendar({node:t.target,field:t.target})},bindOnRangeChange:function(t,e){function n(t,e){BX.html(e,t.value);var n=parseFloat(t.value);var i=parseFloat(t.getAttribute("max"));var a=parseFloat(t.getAttribute("min"));var s=16;var r=i-a;var o=(n-a)/r*100;var c=Math.round(s*o/100)-s/2;e.style.left=o+"%";e.style.marginLeft=-c+"px"}setTimeout(function(){n(t,e)},0);BX.bind(t,"input",function(){n(t,e)})},createImageEditor:function(t){return new BX.Grid.ImageField(this.parent,t).getLayout()},getEditor:function(t,e){var n,i;var a=this.createContainer();if(this.validateEditObject(t)){t.VALUE=t.VALUE===null?"":t.VALUE;switch(t.TYPE){case this.types.TEXT:{n=this.createInput(t);BX.bind(n,"click",function(t){t.stopPropagation()});BX.bind(n,"keydown",BX.delegate(this._onControlKeydown,this));break}case this.types.DATE:{n=this.createInput(t);BX.bind(n,"click",this.initCalendar);BX.bind(n,"click",function(t){t.stopPropagation()});BX.bind(n,"keydown",BX.delegate(this._onControlKeydown,this));break}case this.types.NUMBER:{n=this.createInput(t);BX.bind(n,"click",function(t){t.stopPropagation()});BX.bind(n,"keydown",BX.delegate(this._onControlKeydown,this));break}case this.types.RANGE:{n=this.createInput(t);i=this.createOutput(t);this.bindOnRangeChange(n,i);BX.bind(n,"click",function(t){t.stopPropagation()});BX.bind(n,"keydown",BX.delegate(this._onControlKeydown,this));break}case this.types.CHECKBOX:{n=this.createInput(t);BX.bind(n,"click",function(t){t.stopPropagation()});BX.bind(n,"keydown",BX.delegate(this._onControlKeydown,this));break}case this.types.TEXTAREA:{n=this.createTextarea(t,e);BX.bind(n,"click",function(t){t.stopPropagation()});BX.bind(n,"keydown",BX.delegate(this._onControlKeydown,this));break}case this.types.DROPDOWN:{n=this.createDropdown(t);break}case this.types.IMAGE:{n=this.createImageEditor(t);break}case this.types.CUSTOM:{n=this.createCustom(t);requestAnimationFrame(function(){if(t.HTML){var e=BX.processHTML(t.HTML);e.SCRIPT.forEach(function(t){if(t.isInternal&&t.JS){BX.evalGlobal(t.JS)}})}});BX.bind(n,"click",function(t){t.stopPropagation()});break}default:{break}}}if(BX.type.isDomNode(i)){a.appendChild(i)}if(BX.type.isDomNode(n)){a.appendChild(n)}return a},_onControlKeydown:function(t){if(t.code==="Enter"){t.stopPropagation();t.preventDefault();var e=BX.Grid.Utils.getBySelector(this.parent.getContainer(),"#grid_save_button > button",true);if(e){BX.fireEvent(e,"click")}}}}})();
//# sourceMappingURL=inline-editor.map.js